package com.qcby.myfirstservlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import daoimpl.CarDaoImpl;
import daoimpl.UserDaoImpl;
import pojo.Car;
import pojo.User;

/**
 * Servlet implementation class ShowServlet
 */
@WebServlet("/ShowServlet")
public class ShowServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ShowServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		request.setCharacterEncoding("UTF-8");
		String chezhuID =request.getParameter("chezhuID");
		String jiage =request.getParameter("jiage");
		String pinpai = request.getParameter("pinpai");
		String yanse = request.getParameter("yanse");
		String goucheshijian =request.getParameter("goucheshijian");
		String zhongliang = request.getParameter("zhongliang");
		String zuoweishu = request.getParameter("zuoweishu");
		String chuchangshjian = request.getParameter("chuchangshijian");
		String chejiahao =request.getParameter("chejiahao");
		String ranliao = request.getParameter("ranliao");
		String fadongjihao =request.getParameter("fadongjihao");
		String chepaihao = request.getParameter("chepaihao");
		String shiyongxingzhi =request.getParameter("shiyongxingzhi");
		String paifangdengji = request.getParameter("paifangdengji");
		String nianjianshijian = request.getParameter("nianjianshijian");
		String pinpaixinghao = request.getParameter("pinpaoxinghao");
		String jiagoutedian =request.getParameter("jiegoutedian");
		CarDaoImpl dao = new CarDaoImpl();
		Car car = new Car();
		car.setChezhuID(Integer.parseInt(chezhuID));
		car.setJiage(Integer.parseInt(jiage));
		car.setPinpai(pinpai);
		car.setYanse(yanse);
		car.setGoucheshijian(goucheshijian);
		car.setZhongliang(zhongliang);
		car.setZuoweishu(Integer.parseInt(zuoweishu));
		car.setChuchangshijian(chuchangshjian);
		car.setChejiahao(chejiahao);
		car.setRanliao(ranliao);
		car.setFadongjihao(fadongjihao);
		car.setChepaihao(chepaihao);
		car.setShiyongxingzhi(shiyongxingzhi);
		car.setPaifangdengji(paifangdengji);
		car.setNianjianshijian(nianjianshijian);
		car.setPinpaixinghao(pinpaixinghao);
		car.setJiagoutedian(jiagoutedian);
		int count = dao.addCar(car);
		if (count>0){
		}else {
			request.getRequestDispatcher("test1.jsp").forward(request, response);
			
		}

	}

}
